package com.example.music.adapter

import androidx.fragment.app.Fragment
import androidx.fragment.app.FragmentActivity
import androidx.viewpager2.adapter.FragmentStateAdapter
import com.example.music.fragment.PlaylistFragment
import com.example.music.fragment.RankingFragment
import com.example.music.fragment.RecommendFragment
import com.example.music.fragment.MusicPlayFragment

class MainPagerAdapter(activity: FragmentActivity) : FragmentStateAdapter(activity) {
    private var currentFragment: Fragment? = null

    override fun createFragment(position: Int): Fragment {
        return when (position) {
            0 -> RecommendFragment()
            1 -> MusicPlayFragment().also { currentFragment = it }
            2 -> PlaylistFragment()
            else -> throw IllegalArgumentException("Invalid position $position")
        }
    }

    fun getCurrentFragment(): Fragment? = currentFragment

    override fun getItemCount(): Int = 3
} 